package com.ruoyi.storeIndex.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.storeIndex.domain.Event;
import com.ruoyi.storeIndex.domain.Publish;
import com.ruoyi.storeIndex.service.IStoreStatisticsService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/storeIndex/storeStatistics")
public class StoreStatisticsController extends BaseController {

    @Autowired
    private IStoreStatisticsService storeStatisticsService;
    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 商户端数据总览
     * @return
     */
    @GetMapping("/getAllStatistics")
    public AjaxResult getAllStatistics(){
        Long deptId = SecurityUtils.getDeptId();
        Map<String,Integer> map = new HashMap<>();
        map.put("pendingAuthNum",storeStatisticsService.getPendingAuthNum(deptId));
        map.put("pendingAuthNumAdd",storeStatisticsService.pendingAuthNumAdd(deptId));
        map.put("surveyNum",storeStatisticsService.getSurveyNum(deptId));
        map.put("surveyNumAdd",storeStatisticsService.surveyNumAdd(deptId));
        map.put("completeNum",storeStatisticsService.getCompleteNum(deptId));
        map.put("completeNumAdd",storeStatisticsService.completeNumAdd(deptId));
        return AjaxResult.success(map);
    }

    /**
     * 商户剩余金额
     * @return
     */

    @GetMapping("/getStoreBalance")
    public AjaxResult getStoreBalance(){
        Long deptId = SecurityUtils.getDeptId();
        Map<String, BigDecimal> map = new HashMap<>();
        map.put("storeBalance",storeStatisticsService.getStoreBalance(deptId));
        List<Map> list = new ArrayList<>();
        Map<String,String> map1 = new HashMap<>();
        NumberFormat numberFormat = NumberFormat.getNumberInstance();
        numberFormat.setMaximumFractionDigits(2);
        String result = numberFormat.format(storeStatisticsService.getStoreBalanceChange(deptId).multiply(BigDecimal.valueOf(100)))+"%";
        map1.put("storeBalanceChange",result);
        list.add(map);
        list.add(map1);
        return AjaxResult.success(list);
    }

    /**
     * 公告信息
     * @return
     */
    @GetMapping("/getAnnouncement")
    public AjaxResult getAnnouncement(){
        Long deptId = SecurityUtils.getDeptId();
        Map<String, List<Publish>> map = new HashMap<>();

        map.put("announcement",storeStatisticsService.getAnnouncement(deptId));
        return AjaxResult.success(map);
    }

    /**
     * 活动通知
     * @return
     */
    @GetMapping("/getEventAnnouncement")
    public AjaxResult getEventAnnouncement(){
        Long deptId = SecurityUtils.getDeptId();
        Map<String, List<Event>> map = new HashMap<>();
        map.put("eventAnnouncement",storeStatisticsService.getEventAnnouncement(deptId));
        return AjaxResult.success(map);
    }


}
